<template>
	<div class="factory_case table-theme">
		<head-title title="审核--案例审核"></head-title>
		<el-card>
			<div class="top-menu">
				<div class="menu-left">
					<div class="type-view">
						<tabs-view :list="classifyList" :tabsIndex="status" @roleType="stateType"></tabs-view>
					</div>
				</div>

				<div class="menu-right">
					<refresh-button @refresh="refreshPage"></refresh-button>
				</div>
			</div>
			<p class="data-number">总数据数：{{total}}</p>
			<el-table :data="caseList">
				<el-table-column label="序号" align="center" prop="id"></el-table-column>
				<el-table-column label="案例名称" align="center" prop="case_name"></el-table-column>
				<el-table-column label="主图" align="center" width="80">
					<template slot-scope="scope">
						<ImgPopover :src="scope.row.image_thumb"></ImgPopover>	
					</template>
				</el-table-column>
				<el-table-column label="类型" align="center" prop="type_name"></el-table-column>
				<el-table-column label="提交时间" align="center" prop="add_time"></el-table-column>
				<el-table-column label="审核人" align="center" prop="examine_user_id"></el-table-column>
				<el-table-column label="拒绝原因" align="center" prop="reason"></el-table-column>
				<el-table-column label="审核状态" align="center" prop="status_name"></el-table-column>
				<el-table-column label="操作" align="center" width="280">
					<template slot-scope="scope">
						<el-button type="primary" size="mini" @click="operate(1, scope.row.type_id)">编辑</el-button>
						<el-button type="danger" size="mini" @click="operate(2, scope.row.id)">删除</el-button>
					</template>
				</el-table-column>
			</el-table>
			<div class="pages"><el-pagination background layout="prev, pager, next, jumper" :total="total" @current-change="init" :current-page="page"></el-pagination></div>
		</el-card>
	</div>
</template>

<script>
import ImgPopover from '@/components/ImgPopover';
import TabsView from '@/components/TabsView'
export default {
	components: {
		ImgPopover,
		TabsView
	},
	data() {
		return {
			searchContent: '',
			storeInfo: '', // 展示店铺信息
			storeInfoDialog: false, // 详情弹框
			caseList: [], // 案例审核列表
			total: 0,totalData: 0, 
			status: 0,
			page: 0,
			classifyList: ['全部', '待审核', '审核通过' , '拒绝' ]
		};
	},
	methods: {
		// 初始化列表
		init(e) {
			this.page = e;
			let data = {
				page: e - 1 ? e - 1 : 0,
				limit: 10,
				factory_id: localStorage.getItem('factory_id')
			};
			if (this.status != 0) {
				// status 0 待审核 1 审核通过 2 拒绝
				data.status = this.status - 1;
			}
			if (this.searchContent != '') {
				data.goods_sn = this.searchContent;
			}

			this.$http(this.$ApiList.CaseExamineList, data).then(res => {
				this.caseList = [];
				if (res.datas.length != 0) {
					this.caseList = res.datas.list;
					this.total = res.datas.count;
				}
			});
		},
		stateType(type) {
			this.status = type;
			this.init();
		},
		refreshPage() {
			this.page = 1;
			this.searchContent = '';
			this.status = 0;
			let data = {
				page: 0,
				limit: 10,
				factory_id: localStorage.getItem('factory_id')
			};
			this.$http(this.$ApiList.CaseExamineList, data).then(res => {
				this.caseList = [];
				if (res.datas.length != 0) {
					this.caseList = res.datas.list;
					this.total = res.datas.count;
				}
			});
		},
		operate(type, id) {
			let data = {
				examine_id: id
			};
			//type  1编辑 2删除
			switch (type) {
				case 1:
					this.$router.push({ path: '/case_data', query: { id: id ,type:0} });
					break;
				case 2:
					this.$confirm('此操作将永久删除该评论, 是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					})
						.then(() => {
							this.$http(this.$ApiList.platformExamineDelete, data).then(res => {
								if (res.code == 200) {
									this.$message({
										type: 'success',
										message: '删除成功!'
									});
									this.page = 1;
									this.init();
								}
							});
						})
						.catch(() => {});
					break;
			}
		}
	},
	created() {
		this.init();
	}
};
</script>
<style lang="scss" scoped>
</style>
